//-------------------------------------------------------------------------------------
//autotreasure
function autotreasure()
{
	if (location.href.indexOf("index.php")!=-1) {
		//Check if treasure chest is available to be opened.
		var msg = document.evaluate("//span[@class='message_body']",document,null,9,null).singleNodeValue;
		if (msg!=null) {
			if (msg.innerHTML.indexOf("Ye have unclaimed booty from Poseidon's Chest.")!=-1) {
				addToLog('Treasure chest is available to be opened.');
				window.location = "http://apps.facebook.com/"+SCRIPT.name+"/locks.php";
			}
		}
	}
	
	if (location.href.indexOf("locks.php")!=-1) {
		//Opened treasure chest. Log the treasure.
		var msg = document.evaluate("//span[@class='message_body']",document,null,9,null).singleNodeValue;
		if (msg!=null) {
			if (msg.innerHTML.indexOf('Ye have cracked the set and found a special treasure!')!=-1) {
				var prize = msg.getElementsByTagName('img');
				var prizetitle = prize[1].title;
				var prizeimg = prize[1].src;
				addToLog('Treasure found: '+prizetitle+'<img src="'+prizeimg+'">');
				setTimeout("document.location ='" + "http://apps.facebook.com/"+SCRIPT.name+"/index.php"+"'", 3000);
			}
		}
	}
}

